package com.qidi.ssh.service;

import com.qidi.ssh.bean.SaleVisit;
import com.qidi.ssh.dao.SaleVisitDao;
import com.qidi.ssh.utils.PageBean;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhouXinBin
 * @create 2020-10-21-10:59
 */
@Transactional
public class SaleVisitServiceimpl implements SaleVisitService {
    private SaleVisitDao saleVisitDao;

    public void setSaleVisitDao(SaleVisitDao saleVisitDao) {
        this.saleVisitDao = saleVisitDao;
    }

    @Override
    public PageBean<SaleVisit> listByPage(DetachedCriteria detachedCriteria, Integer pageNo, Integer pageSize) {
        PageBean<SaleVisit> pageBean = new PageBean<>();
        pageBean.setPageNo(pageNo);
        pageBean.setPageSize(pageSize);
        Integer count = saleVisitDao.findCount(detachedCriteria);
        pageBean.setTotalCount(count);
        Double num=Math.ceil(count.doubleValue()/pageSize);
        pageBean.setTotalPage(num.intValue());
        List<SaleVisit> list = saleVisitDao.findByPage(detachedCriteria, pageNo, pageSize);
        pageBean.setList(list);
        return pageBean;
    }

    @Override
    public void save(SaleVisit saleVisit) {
        saleVisitDao.save(saleVisit);
    }

    @Override
    public void delete(String visit_id) {
        SaleVisit saleVisit = saleVisitDao.findById(visit_id);
        saleVisitDao.delete(saleVisit);
    }

    @Override
    public SaleVisit getVisitById(String visit_id) {
        return saleVisitDao.findById(visit_id);
    }
}
